package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;


import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.MsgBean;
import com.mz.ozy.bean.MsgDetailBean;
import com.mz.ozy.bean.OrderMsgBean;
import com.mz.ozy.bean.UnreadMsgBean;
import com.mz.ozy.mvp.model.MsgModel;
import com.mz.ozy.mvp.view.MsgContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class MsgPresenter extends BasePresenterImpl<MsgContract.View> implements MsgContract.Presenter {

    private MsgModel mModel;

    public MsgPresenter() {
        mModel = new MsgModel();
    }


    @Override
    public void getMeInfo(Activity activity, boolean isShow) {
        mModel.getMeInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MeBean>(mView, isShow) {
                    @Override
                    public void onSuccesss(MeBean bean) {
                        mView.getgetMeInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void getMsgList(Activity activity, String type, String pageNo) {
        mModel.getMsgList(activity, type, pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MsgBean>(mView, false) {
                    @Override
                    public void onSuccesss(MsgBean bean) {
                        mView.getMsgrListSuccess(bean);
                    }
                });
    }

    @Override
    public void getOrderMsgList(Activity activity, String pageNo) {
        mModel.getOrderMsgList(activity, pageNo)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<OrderMsgBean>(mView, false) {
                    @Override
                    public void onSuccesss(OrderMsgBean bean) {
                        mView.getOrderMsgrListSuccess(bean);
                    }
                });
    }

    @Override
    public void getMsgDetail(Activity activity, String id) {
        mModel.getMsgDetail(activity, id)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<MsgDetailBean>(mView) {
                    @Override
                    public void onSuccesss(MsgDetailBean jsonObject) {
                        mView.getMsgDetailSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void getAgmentDetail(Activity activity, String id) {
        mModel.getAgmentDetail(activity, id)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.getAgmentDetailSuccess(jsonObject);
                    }
                });
    }
    @Override
    public void getUnreadMsg(Context context) {
        mModel.getUnreadMsg(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<UnreadMsgBean>(mView) {
                    @Override
                    public void onSuccesss(UnreadMsgBean bean) {
                        mView.getUnreadMsgSuccess(bean);
                    }
                });
    }
}
